//https://leetcode.cn/problems/n-ary-tree-level-order-traversal/submissions/574352476/

/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        using ll = long long;
        vector<vector<int>> vv;
        vector<int> v;
        int cur = 1;
        int nxt = 0;
        queue<Node*> q;
        q.push(root);

        while (q.size())
        {
            Node* now = q.front();
            q.pop();
            if (!now)continue;
            int value = now->val;
            v.push_back(value);
            cur--;
            for (auto& next : now->children)
            {
                if (!next)continue;
                nxt++;
                q.push(next);
            }
            if (!cur)
            {
                vv.push_back(v);
                v.clear();
                cur = nxt;
                nxt = 0;
            }
        }

        return vv;
    }
};